using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DecisionMaking.WebApp.Controllers;
using MvcContrib.UI.MenuBuilder;

namespace DecisionMaking.WebApp
{
	public class Navigation
	{
        public static MenuItem MainMenu(UrlHelper url)
        {
            return MainMenu(url, null);
        }

		public static MenuItem MainMenu(UrlHelper url, int? environmentId)
		{
            var route = url.RequestContext.RouteData.Values["Controller"] + "." + url.RequestContext.RouteData.Values["Action"];

			Menu.DefaultIconDirectory = url.Content("~/Content/");
			Menu.DefaultDisabledClass = "disabled";
			Menu.DefaultSelectedClass = "selected";
			return Menu.Begin(
                Menu.Action<AlgorithmsController>(c => c.Index(), "Algorithms"),
                Menu.Action<ReportsController>(c => c.Index(), "Reports"),
                Menu.Action<AccountController>(c => c.Profile(), "My Profile"),
                Menu.Action<HelpController>(c => c.Index(route), "Help"),
                EnvironmentMenu(url, environmentId)
			);
		}

	    private static MenuItem EnvironmentMenu(UrlHelper url, int? environmentId)
        {
            if (environmentId == null)
            {
                return Menu.Action<EnvironmentsController>(c => c.Index(), "My Environments");    
            }
            else
            {
                return Menu.Items("Environments",
                   Menu.Action<EnvironmentsController>(c => c.Index(), "My Environments"),
                   Menu.Action<CueAttributesController>(c => c.List(environmentId.Value), "Cue Attributes"),
                   Menu.Action<CuesController>(c => c.List(environmentId.Value), "Cues"),
                   Menu.Action<CandidatesController>(c => c.List(environmentId.Value), "Candidates"),
                   Menu.Action<AgentsController>(c => c.List(environmentId.Value), "Agents")

                );                
            }
        }
	}
}

